// app/model/user.js
module.exports = (app) => {
	const {
		STRING,
		INTEGER,
		BIGINT,
		DATE,
		DECIMAL
	} = app.Sequelize;
	
	function filterDate(t){
		if(t){
			var date = new Date(t).toLocaleString();
			date = date.replace(/\//g,"-")
			return date;
		}
		return '';
	}
	
	const Groupon = app.model.define("groupon", {
		id: {
			type: INTEGER,
			primaryKey: true,
			autoIncrement: true
		},
		order_id: INTEGER,
		grouponId: INTEGER,
		rulesId: INTEGER,
		userId: INTEGER,
		creatorUserId: INTEGER,
		addTime: {
			type: DATE,
			get() {
				const date = this.getDataValue('addTime');
				return filterDate(date);
			}
		},
		updateTime: {
			type: DATE,
			get() {
				const date = this.getDataValue('updateTime');
				return filterDate(date);
			}
		}
	}, {
		tableName: "dts_groupon",
		paranoid: false,
		timestamps: false,
		freezeTableName: true
	});
	
	// Groupon.hasMany(DtsOrderGoods, {
	// 	foreignKey: 'order_id',
	// 	targetKey: "order_id",
	// })
	// Groupon.associate = function (){
	//   Groupon.hasMany(app.model.DtsOrderGoods, {foreignKey: 'order_id',
	// 	targetKey: "order_id"});
	// }

	return Groupon;
};